package org.skyui.beanmanagers;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;

import org.skyui.accesscontrol.HumanAuthenticator;
import org.skyui.beans.AbstractBean;
import org.skyui.beans.OrganizationBean;
import org.skyui.config.BeansTableViewConfig;


public abstract class AbstractBeanManager<B extends AbstractBean> implements
		Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7209221941549706373L;

	protected Class<B> beanClass;

	protected Map<String, CommandManager> commandManagers;
	private OrganizationBean organization;

	public OrganizationBean getOrganization() {
		return this.organization;
	}

	public void setOrganization(OrganizationBean organization) {
		this.organization = organization;
	}

	public Map<String, CommandManager> getCommandManagers() {
		return this.commandManagers;
	}

	public void addCommandManager(Class commandBeanClass) {
		CommandManager manager = (CommandManager) BeanSetManager.getManager(commandBeanClass, HumanAuthenticator
				.getOrganization());
		if (manager == null)
			throw new Error("Null Manager");
		if (this.commandManagers == null)
			this.commandManagers = new LinkedHashMap<String, CommandManager>();
		this.commandManagers.put(BeansTableViewConfig.getAddItemCaption(manager), manager);
	}

	public Class<B> getBeanClass() {
		return this.beanClass;
	}

	public AbstractBeanManager(Class<B> beanClass) {

		this.beanClass = beanClass;
	}

}
